package net.byg.quartz;

import net.byg.ftp.ContinueFTP;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.io.IOException;

public class Quartz implements Job {

    private static final Logger logger = Logger.getLogger(Quartz.class);

    private static boolean isRunning = false;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        synchronized (this) {
            if (isRunning) {
                logger.info("当前job未完成");
                return;
            }
            isRunning = true;
        }
        ContinueFTP myFtp = new ContinueFTP();
        try {
            logger.info("开始");
            JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
            Object obj = jobDataMap.get("myjob");

        } catch (Exception e) {
            logger.info(e.getMessage());
        } finally {
            try {
                myFtp.disconnect();
            } catch (IOException e) {

            }
            logger.info("结束");
            synchronized (this) {
                isRunning = false;
            }
        }
    }

}
